package model;

import entities.ShiftRequest;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.table.AbstractTableModel;

public class ShiftRequestTableModel extends AbstractTableModel {

    ArrayList<ShiftRequest> list;

    public ShiftRequestTableModel() {
        list = new ArrayList<ShiftRequest>();
    }

    public ShiftRequestTableModel(ArrayList<ShiftRequest> list) {
        this.list = list;
    }

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return 6;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        ShiftRequest sr = list.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return sr.getCreateDate();
            case 1:
                return sr.getStartDate();
            case 2:
                return sr.getEndDate();
            case 3:
                return sr.getShiftName();
            case 4:
                return sr.getStatus();
            case 5:
                return sr.getModifiedDate();
            default:
                return null;
        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return Date.class;
            case 1:
                return Date.class;
            case 2:
                return Date.class;
            case 3:
                return Integer.class;
            case 4:
                return Integer.class;
            case 5:
                return Date.class;
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "CreateDate";
            case 1:
                return "StartDate";
            case 2:
                return "EndDate";
            case 3:
                return "Shift";
            case 4:
                return "Status";
            case 5:
                return "ModifiedDate";
            default:
                return null;
        }
    }

    @Override
    public void fireTableDataChanged() {
        super.fireTableDataChanged();
    }

    public boolean addAll(ArrayList<ShiftRequest> list) {
        boolean returnVal = this.list.addAll(list);
        if (returnVal) {
            fireTableDataChanged();
        }
        return returnVal;
    }

    public boolean addElement(ShiftRequest request) {
        boolean returnVal = list.add(request);
        if (returnVal) {
            fireTableDataChanged();
        }
        return returnVal;
    }

    public ShiftRequest getAt(int index) {
        return list.get(index);
    }

    public void removeAt(int index) {
        list.remove(index);
    }

    public void update(int index, ShiftRequest request) {
        list.set(index, request);
        fireTableDataChanged();
    }

    public void clear() {
        list.clear();
    }
}
